fix: clarify feature flag auth errors#542
Merged
marandaneto merged 1 commit intoPostHog:mainfrom Apr 30, 2026
Merged
Conversation
6 tasks
Contributor
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
posthog/client.py:1353-1370
**Duplicated message content (OnceAndOnlyOnce)**
The error message body — `"Error loading feature flags: {e.message}. Please verify both your project_api_key and personal_api_key. More information: https://posthog.com/docs/api/overview"` — is constructed twice: once as a `%s` format string for the log call, and again as an f-string for the re-raised `APIError`. Extracting it into a local variable eliminates the duplication and keeps the two outputs in sync automatically.
```suggestion
detail = (
f"Error loading feature flags: {e.message}. "
"Please verify both your project_api_key and personal_api_key. "
"More information: https://posthog.com/docs/api/overview"
)
self.log.error("[FEATURE FLAGS] %s", detail)
self.feature_flags = []
self.group_type_mapping = {}
self.cohorts = {}
if self.flag_cache:
self.flag_cache.clear()
if self.debug:
raise APIError(status=401, message=detail)
```
Reviews (1): Last reviewed commit: "fix: clarify feature flag auth errors" | Re-trigger Greptile |
ioannisj
approved these changes
Apr 30, 2026
ioannisj
left a comment
There was a problem hiding this comment.
LG, minor optimization from greptile makes sense
183a31c to
a0554d6
Compare
a0554d6 to
85a961b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Relates to #526.
Local feature flag loading uses both the project API key and the personal/feature-flags API key, but 401 errors always blamed only
personal_api_key. This keeps the server-provided error detail and asks users to verify both credentials.💚 How did you test it?
uv run pytest posthog/test/test_client.py::TestClient::test_load_feature_flags_unauthorized posthog/test/test_feature_flags.py::TestLocalEvaluation::test_load_feature_flags_wrong_key -quv run ruff format --check posthog/client.py posthog/test/test_client.py posthog/test/test_feature_flags.pyuv run ruff check posthog/client.py posthog/test/test_client.py posthog/test/test_feature_flags.py📝 Checklist
If releasing new changes
sampo addto generate a changeset filereleaselabel to the PR